package net.huashitong.user.dao;

import java.util.List;

import net.huashitong.Indicators.filter.EarlyWarnFilter;
import net.huashitong.user.entity.Collection;
import net.huashitong.user.filter.CollectionFilter;

import org.springframework.stereotype.Repository;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;

@Repository
public class CollectionDao extends StringDao<Collection> {

	public List<Collection> queryByUserId(CollectionFilter filter) {
		GenericQuery query = createQuery("obj");
		query.append(" and obj.userId = :userId order By obj.sysId desc").setParam("userId", filter.getUserId());
		return query.listResult();
	}

	public Collection getByuserIdAndAlertId(EarlyWarnFilter filter) {
		GenericQuery query = createQuery("obj");
		query.append(" and obj.userId = :userId").setParam("userId", filter.getUserId());
		query.append(" and obj.alertId = :alertId").setParam("alertId", filter.getSysId());
		return query.singleResult();
	}

	public Collection getByUserIdAndAlertId(CollectionFilter filter) {
		GenericQuery query = createQuery("obj");
		query.append(" and obj.userId = :userId").setParam("userId", filter.getUserId());
		query.append(" and obj.alertId = :alertId").setParam("alertId", filter.getAlertId());
		return query.singleResult();
	}

}
